package org.explugin.lang.lexer;

import com.intellij.lexer.FlexLexer;
import com.intellij.psi.tree.IElementType;
import java.util.*;
import java.lang.reflect.Field;
import org.jetbrains.annotations.NotNull;

%%

%class _ExLexer
%implements FlexLexer
%unicode
%function advance
%type IElementType
%eof{ return;
%eof}

WHITESPACE  =   [\ \r\n\t\f]+
NEWLINE     =   [\r\n|\n\r]
NAME        =   [_a-zA-Z][_a-zA-Z0-9]*
ALGORISM    =   [0-9]+
EXP         =   [Ee][+-]?{ALGORISM}
NUMBER      =   (0[xX][0-9a-fA-F]+|({ALGORISM}|{ALGORISM}[.]{ALGORISM}){EXP}?|[.]{ALGORISM}|{ALGORISM}[.])
STRING      =   [\"\'][^\"\']*[\"\']
COMMENT     =   "#"{NAME}{NEWLINE}

%%

/* Keywords */


"int"           { return ExTokenTypes.TYPE_TOKEN; }
"bool"          { return ExTokenTypes.TYPE_TOKEN; }
"str"           { return ExTokenTypes.TYPE_TOKEN; }
"float"         { return ExTokenTypes.TYPE_TOKEN; }

"var"           { return ExTokenTypes.VAR_TOKEN; }
"func"          { return ExTokenTypes.FUNC_TOKEN; }


"while"         { return ExTokenTypes.WHILE_TOKEN; }
"if"            { return ExTokenTypes.IF_TOKEN; }
"else"          { return ExTokenTypes.ELSE_TOKEN; }

"break"         { return ExTokenTypes.BREAK_TOKEN; }
"continue"      { return ExTokenTypes.CONTINUE_TOKEN; }
"return"        { return ExTokenTypes.RETURN_TOKEN; }

"false"         { return ExTokenTypes.FALSE_TOKEN; }
"true"          { return ExTokenTypes.TRUE_TOKEN; }
{NUMBER}        { return ExTokenTypes.NUMBER_TOKEN; }
{STRING}        { return ExTokenTypes.STRING_TOKEN; }

{WHITESPACE}    { return ExTokenTypes.WHITESPACE; }
{NAME}          { return ExTokenTypes.IDENTIFIER; }
{COMMENT}       { return ExTokenTypes.COMMENT; }

"&&"            { return ExTokenTypes.AND_TOKEN; }
"||"            { return ExTokenTypes.OR_TOKEN; }
"=="            { return ExTokenTypes.EQ_TOKEN; }
">="            { return ExTokenTypes.GE_TOKEN; }
"<="            { return ExTokenTypes.LE_TOKEN; }
">"             { return ExTokenTypes.GT_TOKEN; }
"<"             { return ExTokenTypes.LT_TOKEN; }
"!="            { return ExTokenTypes.NE_TOKEN; }
"-"             { return ExTokenTypes.MINUS_TOKEN; }
"+"             { return ExTokenTypes.PLUS_TOKEN; }
"*"             { return ExTokenTypes.MULT_TOKEN; }
"%"             { return ExTokenTypes.MOD_TOKEN; }
"/"             { return ExTokenTypes.DIV_TOKEN; }
"="             { return ExTokenTypes.ASSIGN_TOKEN; }
"("             { return ExTokenTypes.LPAREN_TOKEN; }
")"             { return ExTokenTypes.RPAREN_TOKEN; }
"{"             { return ExTokenTypes.LCURLY_TOKEN; }
"}"             { return ExTokenTypes.RCURLY_TOKEN; }
","             { return ExTokenTypes.COMMA_TOKEN; }
";"             { return ExTokenTypes.SEMICOLON_TOKEN; }
":"             { return ExTokenTypes.COLON_TOKEN; }

.               { return ExTokenTypes.WRONG; }